package cn.fl.spl.controller;

import cmm.comm.facade.upload.constant.SysUlFilesRecConstant;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spl.service.IAppStatsDataService;
import cn.fl.spl.service.IStoreStatsDataService;
import cn.fl.spl.utils.FileUtil;
import cn.fl.spl.vo.AppStatsDataVO;
import cn.fl.system.constant.SysLogConstant;
import cn.lb.framework.poi.excel.ExcelExportUtil;
import cn.lb.framework.poi.excel.entity.TemplateExportParams;
import cn.lb.framework.poi.excel.entity.enmus.ExcelStyleType;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.mongo.facade.analysis.condition.AppStatsDataCondition;
import fl.mongo.facade.analysis.condition.StoreStatsDataCondition;
import fl.mongo.facade.framework.enums.analysis.AppLiveTypCdEnum;
import fl.mongo.facade.framework.enums.analysis.StoreLiveTypCdNum;
import fl.spl.facade.framework.constant.SplSystemConstant;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by jiangzhongge on 2018-3-2.
 * Time 11:59.
 * Class belongs to fl-ass-service.
 */
@Controller
@RequestMapping(value = "/mongo/appStats")
public class AppStatsDataController extends BaseController {

    @Autowired
    private IAppStatsDataService appStatsDataService;

    @Autowired
    private IStoreStatsDataService storeStatsDataService;


    /**
     * 新增APP统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/addAppStatsDataInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO addAppStatsDataInfo(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, String.valueOf(BaseConstant.IS_YESNO_YES));
        AppStatsDataVO entity = null;
        AppStatsDataCondition condition = null;
        try {
            condition = this.comboConditonForAppStatsData(request);
            if (null == condition) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请求参数不完整");
                return dataResultVO;
            }
            AppStatsDataVO vo = this.appStatsDataService.getOneAppStatsData(condition);
            if (null != vo) {
                vo.setActionDt(new Date());
                vo.setTotalNum(vo.getTotalNum() + 1);
                BaseLogUtils.newWebLogger("新增AppStatsDataVO DATA>>" + JSONObject.toJSONString(vo)).setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .info();

                boolean flag = this.appStatsDataService.upsertAppStatsData(condition, vo);
                if (flag) {
                    BaseLogUtils.newWebLogger("新增AppStatsDataVO成功").setLogOperType(LogOperEnum.RESP)
                            .setSysCd(CurrentThreadContext.getCurrentSysCd())
                            .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                            .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                            .setWarning(false)
                            .info();
                } else {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + "更新数据失败");
                    BaseLogUtils.newWebLogger("新增AppStatsDataVO数据失败.DATA:" + JSONObject.toJSONString(vo)).setLogOperType(LogOperEnum.RESP)
                            .setSysCd(CurrentThreadContext.getCurrentSysCd())
                            .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                            .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                            .setWarning(false)
                            .warn(LogExceptionEnum.COMMON_CODE_0002);
                }
            } else {
                entity = this.comboParamsForAppStatsData(request);//获取参数
                entity.setActionDt(new Date());
                entity.setCrtTm(new Date());
                entity.setTotalNum(1L);
                this.appStatsDataService.insertAppStatsData(entity);
                BaseLogUtils.newWebLogger("新增AppStatsDataVO数据成功.DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .info();
            }
        } catch (BaseException ex) {
            dataResultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newWebLogger("新增AppStatsDataVO数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            dataResultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newWebLogger("新增AppStatsDataVO数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return dataResultVO;
    }

    /**
     * 修改APP统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/modifyAppStatsDataInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO modifyAppStatsDataInfo(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, String.valueOf(BaseConstant.IS_YESNO_YES));
        AppStatsDataVO entity = null;
        try {
            entity = this.comboParamsForAppStatsData(request);//获取参数
            if (null == entity) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请求参数不完整");
                return dataResultVO;
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            entity.setActionDt(new Date());
            entity.setCrtTm(new Date());
            entity.setDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
            entity.setDayOfWeek(calendar.get(Calendar.DAY_OF_WEEK) + 1);
            entity.setYear(calendar.get(Calendar.YEAR));
            entity.setMonth(calendar.get(Calendar.MONTH));
            entity.setWeekPd(calendar.get(Calendar.WEEK_OF_YEAR));
            entity.setTotalNum(1L);
            this.appStatsDataService.insertAppStatsData(entity);
            BaseLogUtils.newWebLogger("新增AppStatsDataInfo数据成功.DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newWebLogger("新增AppStatsDataInfo数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newWebLogger("新增AppStatsDataInfo数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(ex)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
        }
        return dataResultVO;
    }

    /**
     * 初始化APP数据统计信息页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/initDataAnalysisPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ModelAndView initDataAnalysisPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("spl/analysis/dataStatisticsPage");
        return modelAndView;
    }

    /**
     * 到数据统计页
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mav = new ModelAndView();
        String dayRegion = request.getParameter("dayRegion");
        String queryType = request.getParameter("queryType");
        if ("1".equals(queryType)) {//概览页
            mav.setViewName("spl/analysis/app/appDataAnalysis");
        } else if ("2".equals(queryType)) {//绩效明细报表
            mav.setViewName("spl/analysis/spl/splDataAnalysis");
        }else if("3".equals(queryType)){
        	mav.setViewName("spl/analysis/app/moreDataAnalysis");
        	mav.addObject("dayRegion", dayRegion);
        }
        return mav;
    }

    /**
     * 获取APP数据统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getAppStatsDataInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO getAppStatsDataInfo(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, String.valueOf(BaseConstant.IS_YESNO_YES));
        String dayRegion = request.getParameter("dayRegion");
        String dateMin = request.getParameter("dateMin");
        String dateMax = request.getParameter("dateMax");
        AppStatsDataCondition condition = new AppStatsDataCondition();
        StoreStatsDataCondition storeStatsDataCondition = new StoreStatsDataCondition();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        condition.setAppSysCd(SplSystemConstant.SPL_SHOP_APP_CD);
        //APP装机量
        condition.setLiveType(AppLiveTypCdEnum.INSTALL.name());
        Long insNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_YES);
        //注册用户总数
        condition.setLiveType(AppLiveTypCdEnum.REGISTER.name());
        Long regNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        if (StringUtils.isNotEmpty(dayRegion)) {
            if ("1".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -1);
            } else if ("7".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -7);
            } else if ("15".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -15);
            } else if ("30".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -30);
            }
            condition.setCrtTmMin(calendar.getTime());
            if("1".equals(dayRegion)){
            	condition.setCrtTmMax(calendar.getTime());
            }else{
            	condition.setCrtTmMax(new Date());
            }
            storeStatsDataCondition.setCrtTmMin(calendar.getTime());
            storeStatsDataCondition.setCrtTmMax(new Date());
        } else {
            if (StringUtils.isEmpty(dateMin) && StringUtils.isEmpty(dateMax)) {
                calendar.add(Calendar.DAY_OF_MONTH, -1);
                condition.setCrtTmMin(calendar.getTime());
                condition.setCrtTmMax(new Date());
                storeStatsDataCondition.setCrtTmMin(calendar.getTime());
                storeStatsDataCondition.setCrtTmMax(new Date());
            }
        }
        if (StringUtils.isEmpty(dayRegion) && (StringUtils.isNotEmpty(dateMin) || StringUtils.isNotBlank(dateMax))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                if (StringUtils.isNotEmpty(dateMin)) {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMin = dateMin + " 00:00:00";
                        dateMax = dateMax + " 00:00:00";
                        condition.setCrtTmMin(sdf.parse(dateMin));
                        condition.setCrtTmMax(sdf.parse(dateMax));
                        storeStatsDataCondition.setCrtTmMin(sdf.parse(dateMin));
                        storeStatsDataCondition.setCrtTmMax(sdf.parse(dateMax));
                    } else {
                        dateMin = dateMin + " 00:00:00";
                        condition.setCrtTmMin(sdf.parse(dateMin));
                        condition.setCrtTmMax(new Date());
                        storeStatsDataCondition.setCrtTmMin(sdf.parse(dateMin));
                        storeStatsDataCondition.setCrtTmMax(new Date());
                    }
                } else {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMax = dateMax + " 00:00:00";
                        condition.setCrtTmMax(sdf.parse(dateMax));
                        storeStatsDataCondition.setCrtTmMax(sdf.parse(dateMax));
                    }
                }
            } catch (ParseException pe) {
                pe.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //新增注册用户
        Long newRegNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        storeStatsDataCondition.setSplId(null);
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.CONSULT.name());
        //总电话拨号量 TODO
        Long conTelNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);
        //基础信息认证
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.FSTCERT.name());
        Long fstCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);
        //账号信息认证
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.SECCERT.name());
        Long secCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);

        //30天内活跃用户
        StoreStatsDataCondition condition2 = new StoreStatsDataCondition();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -30);
        condition2.setActionDtMin(calendar.getTime());
        condition2.setLiveType(StoreLiveTypCdNum.WELCOME.name());
        condition2.setActionDtMax(new Date());
        //Long liveUsrNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        Long liveUsrNum = this.storeStatsDataService.searchActiveUsrCount(condition2);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("insNum", insNum == null ? 0L : insNum);
        jsonObject.put("regNum", regNum == null ? 0L : regNum);
        jsonObject.put("newRegNum", newRegNum == null ? 0L : newRegNum);
        jsonObject.put("conTelNum", conTelNum == null ? 0L : conTelNum);
        jsonObject.put("fstCertNum", fstCertNum == null ? 0L : fstCertNum);
        jsonObject.put("secCertNum", secCertNum == null ? 0L : secCertNum);
        jsonObject.put("liveUsrNum", liveUsrNum == null ? 0L : liveUsrNum);
        dataResultVO.setData(jsonObject);
        BaseLogUtils.newWebLogger("统计数据DATA>>" + JSONObject.toJSONString(dataResultVO)).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();

        return dataResultVO;
    }

    /**
     * 导出数据统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/exportAppStatsDataListBak.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportAppStatsDataListBak(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, String.valueOf(BaseConstant.IS_YESNO_YES));
        String dayRegion = request.getParameter("dayRegion");
        String dateMin = request.getParameter("dateMin");
        String dateMax = request.getParameter("dateMax");
        AppStatsDataCondition condition = new AppStatsDataCondition();
        StoreStatsDataCondition storeStatsDataCondition = new StoreStatsDataCondition();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        condition.setAppSysCd(SplSystemConstant.SPL_SHOP_APP_CD);
        //APP装机量
        condition.setLiveType(AppLiveTypCdEnum.INSTALL.name());
        Long insNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_YES);
        //注册用户总数
        condition.setLiveType(AppLiveTypCdEnum.REGISTER.name());
        Long regNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        if (StringUtils.isNotEmpty(dayRegion)) {
            if ("1".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -1);
            } else if ("7".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -7);
            } else if ("15".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -15);
            } else if ("30".equals(dayRegion)) {
                calendar.add(Calendar.DAY_OF_MONTH, -30);
            }
            condition.setCrtTmMin(calendar.getTime());
            condition.setCrtTmMax(new Date());
            storeStatsDataCondition.setCrtTmMin(calendar.getTime());
            storeStatsDataCondition.setCrtTmMax(new Date());
        } else {
            if (StringUtils.isEmpty(dateMin) && StringUtils.isEmpty(dateMax)) {
                calendar.add(Calendar.DAY_OF_MONTH, -1);
                condition.setCrtTmMin(calendar.getTime());
                condition.setCrtTmMax(new Date());
                storeStatsDataCondition.setCrtTmMin(calendar.getTime());
                storeStatsDataCondition.setCrtTmMax(new Date());
            }
        }
        if (StringUtils.isEmpty(dayRegion) && (StringUtils.isNotEmpty(dateMin) || StringUtils.isNotBlank(dateMax))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                if (StringUtils.isNotEmpty(dateMin)) {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMin = dateMin + " 00:00:00";
                        dateMax = dateMax + " 00:00:00";
                        condition.setCrtTmMin(sdf.parse(dateMin));
                        condition.setCrtTmMax(sdf.parse(dateMax));
                        storeStatsDataCondition.setCrtTmMin(sdf.parse(dateMin));
                        storeStatsDataCondition.setCrtTmMax(sdf.parse(dateMax));
                    } else {
                        dateMin = dateMin + " 00:00:00";
                        condition.setCrtTmMin(sdf.parse(dateMin));
                        condition.setCrtTmMax(new Date());
                        storeStatsDataCondition.setCrtTmMin(sdf.parse(dateMin));
                        storeStatsDataCondition.setCrtTmMax(new Date());
                    }
                } else {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMax = dateMax + " 00:00:00";
                        condition.setCrtTmMax(sdf.parse(dateMax));
                        storeStatsDataCondition.setCrtTmMax(sdf.parse(dateMax));
                    }
                }
            } catch (ParseException pe) {
                pe.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //新增注册用户
        Long newRegNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        storeStatsDataCondition.setSplId(null);
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.CONSULT.name());
        //总电话拨号量 TODO
        Long conTelNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);
        //基础信息认证
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.FSTCERT.name());
        Long fstCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);
        //账号信息认证
        storeStatsDataCondition.setLiveType(StoreLiveTypCdNum.SECCERT.name());
        Long secCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeStatsDataCondition);

        //30天内活跃用户
        StoreStatsDataCondition condition2 = new StoreStatsDataCondition();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -30);
        condition2.setCrtTmMin(calendar.getTime());
        condition2.setLiveType(StoreLiveTypCdNum.WELCOME.name());
        condition2.setCrtTmMax(new Date());
        //Long liveUsrNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
        Long liveUsrNum = this.storeStatsDataService.searchActiveUsrCount(condition2);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("insNum", insNum == null ? 0L : insNum);
        jsonObject.put("regNum", regNum == null ? 0L : regNum);
        jsonObject.put("newRegNum", newRegNum == null ? 0L : newRegNum);
        jsonObject.put("conTelNum", conTelNum == null ? 0L : conTelNum);
        jsonObject.put("fstCertNum", fstCertNum == null ? 0L : fstCertNum);
        jsonObject.put("secCertNum", secCertNum == null ? 0L : secCertNum);
        jsonObject.put("liveUsrNum", liveUsrNum == null ? 0L : liveUsrNum);
        dataResultVO.setData(jsonObject);
        BaseLogUtils.newWebLogger("统计数据导出DATA>>" + JSONObject.toJSONString(dataResultVO)).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();

        //导出数据
        Map<String, Object> map = new HashMap<String, Object>();
        FileOutputStream fos = null;
        map.put("insNum", insNum == null ? 0L : insNum);
        map.put("regNum", regNum == null ? 0L : regNum);
        map.put("newRegNum", newRegNum == null ? 0L : newRegNum);
        map.put("conTelNum", conTelNum == null ? 0L : conTelNum);
        map.put("fstCertNum", fstCertNum == null ? 0L : fstCertNum);
        map.put("secCertNum", secCertNum == null ? 0L : secCertNum);
        map.put("liveUsrNum", liveUsrNum == null ? 0L : liveUsrNum);

        String tempPath = "template/spl/appStatsData/appStatsData.xlsx";
        TemplateExportParams params = new TemplateExportParams(tempPath, false, "数据统计");
        params.setHeadingRows(0);
        params.setHeadingStartRow(1);
        params.setStyle(ExcelStyleType.BORDER.getClazz());
        params.setColForEach(true);//注：包含遍历list
        //文件保存路径
        String filePath = "analysis/";
        String serverFilePath = FileUtil.getServerFilePath(filePath);
        serverFilePath = serverFilePath + "APPANLAY" + System.currentTimeMillis() + ".xlsx";
        try {
            Workbook book = ExcelExportUtil.exportExcel(params, map);
            fos = new FileOutputStream(serverFilePath);
            book.write(fos);
            fos.flush();
        } catch (FileNotFoundException e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        } catch (IOException e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        } catch (Exception e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        }finally {
            try {
                if (null != fos) {
                    fos.close();
                }
            } catch (IOException e) {
                BaseLogUtils.newWebLogger("业务异常").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setThrowable(e)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        }
        serverFilePath = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),
                PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_SERVER_PATH));
        BaseLogUtils.newWebLogger("导出统计数据,返回服务器路径.serverPath:" + serverFilePath).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();

        dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
        dataResultVO.setInfo("导出统计数据成功");
        dataResultVO.setData(serverFilePath);
        return dataResultVO;
    }

    /**
     * 导出数据统计信息
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/exportAppStatsDataList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportAppStatsDataList(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, String.valueOf(BaseConstant.IS_YESNO_YES));
        String dayRegion = request.getParameter("dayRegion");
        String dateMin = request.getParameter("dateMin");
        String dateMax = request.getParameter("dateMax");
        AppStatsDataCondition condition = new AppStatsDataCondition();
        StoreStatsDataCondition storeStatsDataCondition = new StoreStatsDataCondition();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        Calendar calendarLast = Calendar.getInstance();
        calendarLast.setTime(new Date());
        String formatStr = "yyyy-MM-dd HH:mm:ss";
        if(StringUtils.isNotEmpty(dateMin) || StringUtils.isNotEmpty(dateMax)){
            //按时间段查询
            try {
                if (StringUtils.isNotEmpty(dateMin)) {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMin = dateMin + " 00:00:00";
                        dateMax = dateMax + " 00:00:00";
                        if(compareDate(dateMin,DateUtils.formatDateToString(calendar.getTime(),formatStr),formatStr) == 1){
                            if(compareDate(dateMax,DateUtils.formatDateToString(calendar.getTime(),formatStr),formatStr) == 1){
                                calendar.setTime(DateUtils.formatStringToDate(dateMax,formatStr));
                                calendarLast.setTime(DateUtils.formatStringToDate(dateMin,formatStr));
                            }else{
                                calendarLast.setTime(DateUtils.formatStringToDate(dateMin,formatStr));
                            }
                        }
                    } else {
                        dateMin = dateMin + " 00:00:00";
                        if(compareDate(dateMin,DateUtils.formatDateToString(calendar.getTime(),formatStr),formatStr) == 1){
                            calendarLast.setTime(DateUtils.formatStringToDate(dateMin,formatStr));
                        }
                    }
                } else {
                    if (StringUtils.isNotEmpty(dateMax)) {
                        dateMax = dateMax + " 00:00:00";
                        if(compareDate(dateMax,DateUtils.formatDateToString(calendar.getTime(),formatStr),formatStr) == 1){
                            calendar.setTime(DateUtils.formatStringToDate(dateMax,formatStr));
                            calendarLast.setTime(DateUtils.formatStringToDate(dateMax,formatStr));
                            calendarLast.add(Calendar.DAY_OF_MONTH, -1);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else{
            if(StringUtils.isNotEmpty(dayRegion)){
                //按天数范围查询
                if ("1".equals(dayRegion)) {
                    calendarLast.add(Calendar.DAY_OF_MONTH, -1);
                } else if ("7".equals(dayRegion)) {
                    calendarLast.add(Calendar.DAY_OF_MONTH, -7);
                } else if ("15".equals(dayRegion)) {
                    calendarLast.add(Calendar.DAY_OF_MONTH, -15);
                } else if ("30".equals(dayRegion)) {
                    calendarLast.add(Calendar.DAY_OF_MONTH, -30);
                }
            }else{
                //查询昨天的数据
                calendarLast.add(Calendar.DAY_OF_MONTH, -1);
            }
        }
        Long days = DateUtils.getDaysBetweenTwoDates(calendarLast.getTime(),calendar.getTime());

        List<Map<String,Object>> analysisDataList = getAnalysisDataList(condition, storeStatsDataCondition, days, calendarLast, calendar);
        Map<String,Object> exportMap = new HashMap<>();
        exportMap.put("maplist", analysisDataList);
        exportMap.put("exportTm", DateUtils.formatDateToString(new Date(),"yyyy-MM-dd"));
        FileOutputStream fos = null;
        String tempPath = "template/spl/appStatsData/appStatsData.xlsx";
        TemplateExportParams params = new TemplateExportParams(tempPath, false, "数据统计");
        params.setHeadingRows(0);
        params.setHeadingStartRow(1);
        params.setStyle(ExcelStyleType.BORDER.getClazz());
        params.setColForEach(true);//注：包含遍历list
        //文件保存路径
        String filePath = "analysis/";
        String serverFilePath = FileUtil.getServerFilePath(filePath);
        serverFilePath = serverFilePath + "APPANLAY" + System.currentTimeMillis() + ".xlsx";
        try {
            Workbook book = ExcelExportUtil.exportExcel(params, exportMap);
            fos = new FileOutputStream(serverFilePath);
            book.write(fos);
            fos.flush();
        } catch (FileNotFoundException e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        } catch (IOException e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        } catch (Exception e) {
            BaseLogUtils.newWebLogger("导出统计数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .setThrowable(e)
                    .error(LogExceptionEnum.COMMON_CODE_0099);
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_700, e.getMessage());
        } finally {
            try {
                if (null != fos) {
                    fos.close();
                }
            } catch (IOException e) {
                BaseLogUtils.newWebLogger("异常").setLogOperType(LogOperEnum.REQ)
                        .setSysCd(CurrentThreadContext.getCurrentSysCd())
                        .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                        .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                        .setWarning(false)
                        .setThrowable(e)
                        .warn(LogExceptionEnum.COMMON_CODE_0002);
            }
        }
        serverFilePath = serverFilePath.replace(PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH),
                PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_SERVER_PATH));
        BaseLogUtils.newWebLogger("导出统计数据,返回服务器路径.serverPath:" + serverFilePath).setLogOperType(LogOperEnum.RESP)
                .setSysCd(CurrentThreadContext.getCurrentSysCd())
                .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                .setWarning(false)
                .info();

        dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
        dataResultVO.setInfo("导出统计数据成功");
        dataResultVO.setData(serverFilePath);
        return dataResultVO;
    }

    private AppStatsDataVO comboParamsForAppStatsData(HttpServletRequest request) {
        String appSysCd = request.getParameter("appSysCd");
        String appVersion = request.getParameter("appVersion");
        String dataId = request.getParameter("dataId");
        String equipSysTyp = request.getParameter("equipSysTyp");
        String equipTyp = request.getParameter("equipTyp");
        String equipVersion = request.getParameter("equiequipVersionpTyp");
        String usrId = request.getParameter("usrId");
        String liveType = request.getParameter("liveType");
        String source = request.getParameter("source");
        String localProvince = request.getParameter("localProvince");
        String localCity = request.getParameter("localCity");
        AppStatsDataVO appStatsDataVO = new AppStatsDataVO();
        if (StringUtils.isNotEmpty(appSysCd)) {
            appStatsDataVO.setAppSysCd(appSysCd);
        }
        if (StringUtils.isNotEmpty(appVersion)) {
            appStatsDataVO.setAppVersion(appVersion);
        }
        if (StringUtils.isNotEmpty(dataId)) {
            appStatsDataVO.setDataId(dataId);
        }
        if (StringUtils.isNotEmpty(equipSysTyp)) {
            appStatsDataVO.setEquipSysTyp(equipSysTyp);
        }
        if (StringUtils.isNotEmpty(equipTyp)) {
            appStatsDataVO.setEquipTyp(equipTyp);
        }
        if (StringUtils.isNotEmpty(equipVersion)) {
            appStatsDataVO.setEquipVersion(equipVersion);
        }
        if (StringUtils.isNotEmpty(liveType)) {
            appStatsDataVO.setLiveType(liveType);
        }
        if (StringUtils.isNotEmpty(source)) {
            appStatsDataVO.setSource(source);
        }
        if (StringUtils.isNotEmpty(localProvince)) {
            appStatsDataVO.setLocalProvince(localProvince);
        }
        if (StringUtils.isNotEmpty(localCity)) {
            appStatsDataVO.setLocalCity(localCity);
        }
        if (StringUtils.isNotEmpty(usrId)) {
            appStatsDataVO.setUsrId(Long.valueOf(usrId));
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        appStatsDataVO.setDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
        appStatsDataVO.setDayOfWeek(calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1);
        appStatsDataVO.setYear(calendar.get(Calendar.YEAR));
        appStatsDataVO.setMonth(calendar.get(Calendar.MONTH) + 1);
        appStatsDataVO.setWeekPd(calendar.get(Calendar.WEEK_OF_YEAR));
        return appStatsDataVO;
    }

    private AppStatsDataCondition comboConditonForAppStatsData(HttpServletRequest request) {
        String appSysCd = request.getParameter("appSysCd");
        String appVersion = request.getParameter("appVersion");
        String dataId = request.getParameter("dataId");
        String equipSysTyp = request.getParameter("equipSysTyp");
        String equipTyp = request.getParameter("equipTyp");
        String equipVersion = request.getParameter("equiequipVersion");
        String usrId = request.getParameter("usrId");
        String liveType = request.getParameter("liveType");
        String source = request.getParameter("source");
        String localProvince = request.getParameter("localProvince");
        String localCity = request.getParameter("localCity");
        AppStatsDataCondition condition = new AppStatsDataCondition();
        if (StringUtils.isNotEmpty(appSysCd)) {
            condition.setAppSysCd(appSysCd);
        }
        if (StringUtils.isNotEmpty(appVersion)) {
            condition.setAppVersion(appVersion);
        }
        if (StringUtils.isNotEmpty(dataId)) {
            condition.setDataId(dataId);
        }
        if (StringUtils.isNotEmpty(equipSysTyp)) {
            condition.setEquipSysTyp(equipSysTyp);
        }
        if (StringUtils.isNotEmpty(equipTyp)) {
            condition.setEquipTyp(equipTyp);
        }
        if (StringUtils.isNotEmpty(equipVersion)) {
            condition.setEquipVersion(equipVersion);
        }
        if (StringUtils.isNotEmpty(liveType)) {
            condition.setLiveType(liveType);
        }
        if (StringUtils.isNotEmpty(source)) {
            condition.setSource(source);
        }
        if (StringUtils.isNotEmpty(localProvince)) {
            condition.setLocalProvince(localProvince);
        }
        if (StringUtils.isNotEmpty(localCity)) {
            condition.setLocalCity(localCity);
        }
        if (StringUtils.isNotEmpty(usrId)) {
            condition.setUsrId(Long.valueOf(usrId));
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        condition.setDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
        condition.setDayOfWeek(calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1);
        condition.setYear(calendar.get(Calendar.YEAR));
        condition.setMonth(calendar.get(Calendar.MONTH) + 1);
        condition.setWeekPd(calendar.get(Calendar.WEEK_OF_YEAR));
        return condition;
    }

    private int compareDate(String date1, String date2,String formatStr) {
        SimpleDateFormat df = new SimpleDateFormat(formatStr);
        try {
            Date dt1 = df.parse(date1);
            Date dt2 = df.parse(date2);
            if (dt1.getTime() > dt2.getTime()) {
                //System.out.println("dt1 在dt2前");
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                //System.out.println("dt1在dt2后");
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }

    private List<Map<String,Object>> getAnalysisDataList(AppStatsDataCondition appCondition,StoreStatsDataCondition storeCondition,
                                                         Long days,Calendar lastCalendar,Calendar calendar){
        List<Map<String,Object>> analysisDataList = new ArrayList<>();
        appCondition.setAppSysCd(SplSystemConstant.SPL_SHOP_APP_CD);
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        Calendar calendar3 = Calendar.getInstance();
        calendar2.setTime(lastCalendar.getTime());
        for(int i=1; i<=days ;i++){
            //导出数据
            Map<String, Object> map = new HashMap<String, Object>();
            calendar1.setTime(lastCalendar.getTime());
            if(i == days){
                calendar2.setTime(calendar.getTime());
            }else{
                calendar2.add(Calendar.DAY_OF_MONTH, 1);
            }
            appCondition.setCrtTmMin(calendar1.getTime());
            appCondition.setCrtTmMax(calendar2.getTime());
            storeCondition.setCrtTmMin(calendar1.getTime());
            storeCondition.setCrtTmMax(calendar2.getTime());

            //APP装机量
            appCondition.setLiveType(AppLiveTypCdEnum.INSTALL.name());
            Long insNum = this.appStatsDataService.statisAppStatsDataCount(appCondition,BaseConstant.IS_YESNO_YES);
            //注册用户总数
            appCondition.setLiveType(AppLiveTypCdEnum.REGISTER.name());
            Long regNum = this.appStatsDataService.statisAppStatsDataCount(appCondition,BaseConstant.IS_YESNO_NO);

            //新增注册用户
            Long newRegNum = this.appStatsDataService.statisAppStatsDataCount(appCondition,BaseConstant.IS_YESNO_NO);
            storeCondition.setSplId(null);
            storeCondition.setLiveType(StoreLiveTypCdNum.CONSULT.name());
            //总电话拨号量 TODO
            Long conTelNum = this.storeStatsDataService.statisStoreStatsDataCount(storeCondition);
            //基础信息认证
            storeCondition.setLiveType(StoreLiveTypCdNum.FSTCERT.name());
            Long fstCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeCondition);
            //账号信息认证
            storeCondition.setLiveType(StoreLiveTypCdNum.SECCERT.name());
            Long secCertNum = this.storeStatsDataService.statisStoreStatsDataCount(storeCondition);

            //30天内活跃用户
            StoreStatsDataCondition condition2 = new StoreStatsDataCondition();
            calendar3.setTime(calendar1.getTime());
            calendar3.add(Calendar.DAY_OF_MONTH, -30);
            condition2.setCrtTmMin(calendar3.getTime());
            condition2.setLiveType(StoreLiveTypCdNum.WELCOME.name());
            condition2.setCrtTmMax(new Date());
            //Long liveUsrNum = this.appStatsDataService.statisAppStatsDataCount(condition,BaseConstant.IS_YESNO_NO);
            Long liveUsrNum = this.storeStatsDataService.searchActiveUsrCount(condition2);
            
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("insNum", insNum == null ? 0L : insNum);
            jsonObject.put("regNum", regNum == null ? 0L : regNum);
            jsonObject.put("newRegNum", newRegNum == null ? 0L : newRegNum);
            jsonObject.put("conTelNum", conTelNum == null ? 0L : conTelNum);
            jsonObject.put("fstCertNum", fstCertNum == null ? 0L : fstCertNum);
            jsonObject.put("secCertNum", secCertNum == null ? 0L : secCertNum);
            jsonObject.put("liveUsrNum", liveUsrNum == null ? 0L : liveUsrNum);

            BaseLogUtils.newWebLogger("统计数据导出DATA>>" + JSONObject.toJSONString(jsonObject)).setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();

            map.put("exportDt",DateUtils.formatDateToString(calendar1.getTime(),"yyyy-MM-dd"));
            map.put("insNum", insNum == null ? 0L : insNum);
            map.put("regNum", regNum == null ? 0L : regNum);
            map.put("newRegNum", newRegNum == null ? 0L : newRegNum);
            map.put("conTelNum", conTelNum == null ? 0L : conTelNum);
            map.put("fstCertNum", fstCertNum == null ? 0L : fstCertNum);
            map.put("secCertNum", secCertNum == null ? 0L : secCertNum);
            map.put("liveUsrNum", liveUsrNum == null ? 0L : liveUsrNum);

            analysisDataList.add(map);
            map = null ;
            jsonObject = null ;

            lastCalendar.add(Calendar.DAY_OF_MONTH,1);
        }
        calendar = null ;
        calendar1 = null ;
        calendar2 = null ;
        lastCalendar = null ;
        calendar3 = null ;
        return analysisDataList ;
    }
    
}